<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH . 'models/m_select.php';

/**
 * Модель выборки стран видео
 *
 * @package CoreFramework
 * @version 1.0
 * @author Gennadiy Kozlenko
 */
class M_Select_Countries extends M_Select {
   
   /**
    * Конструктор класса
    *
    * @access public
    * @return M_Select_Countries
    */
   function M_Select_Countries() {
      parent::M_Select();
      $this->load->language('select_countries');
      // Устанавливаем запрос
      $sql = "
         SELECT
            c.id_country AS id,
            c.title,
            c.slug,
            SUM(IF(v.status = 'active', 1, 0)) AS videos,
            COUNT(v.id_video) AS videos_hidden
         FROM
            " . $this->db->dbprefix('countries') . " c
               LEFT JOIN " . $this->db->dbprefix('video_countries') . " vc ON (vc.id_country = c.id_country)
               LEFT JOIN " . $this->db->dbprefix('videos') . " v ON (v.id_video = vc.id_video AND v.status <> 'deleted')
         GROUP BY
            c.id_country
      ";
      parent::set_sql($sql);
   } // end M_Select_Sources
   
   /**
    * Установка SQL запроса
    *
    * @access public
    * @param string $table
    */
   function set_sql($sql) {
      
   } // end set_sql
   
   /**
    * Обработка результата
    *
    * @access protected
    * @param array $result
    */
   function _process_result(&$result) {
      $result['videos'] = $result['videos'] . ' (' . $result['videos_hidden'] . ')';
   } // end _process_result
   
}
